﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_PersonJobSrhForm
 * 类型：       控制层
 * 功能说明：   职位信息列表页面
 * 作者：       黄鑫
 * 创建日期：   2007/10/30
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using log4net;
using Shpm.App.Commons.Utils;

public partial class App_Input_PersonJobSrhForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_PersonJobSrhForm));

    private const string SELECT_ALL = "-1";

    // page load
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!Page.IsPostBack)
        {
            initPageControls();
        }
    }

    // bind common catalog data 
    private void initPageControls()
    {
        PersonJobDao dao = new PersonJobDao();
        PersonJobBean bean = new PersonJobBean();
        IList lstJob1 = dao.ListJob(bean);
        lstJob1.Insert(0,new PersonJobBean());
        IList lstGroup1 = dao.ListGroup(bean);
        lstGroup1.Insert(0, new PersonJobBean());

        // 职位列表
        lstJob.DataSource = lstJob1;
        lstJob.DataBind();

        // 部门列表
        lstGroup.DataSource = lstGroup1;
        lstGroup.DataBind();

    }


    // before render
    void Page_PreRender(object sender, EventArgs e)
    {
        // get current doctor responsibility members list
        PersonJobDao dao = new PersonJobDao();
        IList lstRst = null;
        PersonJobBean bean = new PersonJobBean();
        if (! string.IsNullOrEmpty(Convert.ToString(this.ViewState["GROUP_ID"])))
        {
            bean.DepartId = Convert.ToString(this.ViewState["GROUP_ID"]);
        }
        if (! string.IsNullOrEmpty(Convert.ToString(this.ViewState["JOB_ID"])))
        {
            bean.JobId = Convert.ToInt32(this.ViewState["JOB_ID"]);
        }
        lstRst = dao.ListResult(bean);
        if (lstRst.Count == 0)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0034").ToString();
        }
        else
        {
            viewSrhRst.DataSource = lstRst;
            viewSrhRst.DataBind();
        }
        setLstJob(bean.DepartId,Convert.ToString(bean.JobId));
    }

    // page index change
    protected void viewSrhRst_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        viewSrhRst.PageIndex = e.NewPageIndex;
    }  

    // adjust bind data
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            PersonJobBean bean = (PersonJobBean)e.Row.DataItem;
            (e.Row.FindControl("selectImg") as ImageButton).Attributes.Add("onclick", "selectJob('" + bean.JobId + "','"+bean.JobName+"')");
        }
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        this.ViewState["GROUP_ID"] = lstGroup.SelectedValue;
        this.ViewState["JOB_ID"] = lstJob.SelectedValue;
    }

    protected void setLstJob(string groupId,string jobId)
    {
        PersonJobDao dao = new PersonJobDao();
        PersonJobBean bean = new PersonJobBean();
        bean.GroupId = groupId;
        IList lstJob1 = dao.ListJob(bean);
        lstJob1.Insert(0, new PersonJobBean());


        // 职位列表
        lstJob.DataSource = lstJob1;
        lstJob.DataBind();
        if (!string.IsNullOrEmpty(Convert.ToString(jobId)))
        {
            lstJob.SelectedValue = Convert.ToString(jobId);
        }
    }
}
